using System;
using System.Linq;
using CommandSystem;

namespace RgCore.GameModes.Commands.GameModeCommands
{
    public class Set : ICommand
    {
        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            if (!sender.CheckPermission(PlayerPermissions.RoundEvents))
            {
                response = "你必须拥有回合控制权限才能修改游戏模式";
                return false;
            }

            if (arguments.Count < 1)
            {
                response = "gamemode set 游戏模式ID";
                return false;
            }

            var gameMode = GameMode.AllGameModes.FirstOrDefault(x => x.Name == arguments.At(0));
            if (gameMode == null)
            {
                response = "没有找到指定游戏模式！请输入gamemode list查询ID表";
                return false;
            }

            if (GameMode.NextGameMode == gameMode)
            {
                response = "下一个模式已经是指定模式了！";
                return false;
            }

            GameMode.SetNextGameMode(gameMode);
            response = "已设置！";
            return true;
        }

        public string Command { get; } = "set";
        public string[] Aliases { get; } = Array.Empty<string>();
        public string Description { get; } = "设置游戏模式";
    }
}